package com.plugin.seed.web.configuration;

import com.plugin.seed.web.support.AbstractLoginUserMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author Peter Fan
 */
@Configuration
public class LoginUserArgumentConfigurer implements WebMvcConfigurer {

    @Autowired
    private ApplicationContext applicationContext;


    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        AbstractLoginUserMethodArgumentResolver abstractLoginUserMethodArgumentResolver = applicationContext.getBean(AbstractLoginUserMethodArgumentResolver.class);
        if (abstractLoginUserMethodArgumentResolver != null) {
            resolvers.add(abstractLoginUserMethodArgumentResolver);
        }
    }
}
